package com.miquan.minotehelper;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;

import com.miquan.minotehelper.activity.SuperActivity;
import com.miquan.minotehelper.service.ScreenShotService;

public class MainActivity extends SuperActivity implements View.OnClickListener {
    private static final int NOTIFICATION_ID = 100;

    private NotificationManager mNotificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initNotification();
        initServices();

        // --- test ---
        // 测试一下
//        ClipImageActivity.startInNewTask(context, "/storage/emulated/0/MINoteHelper/1438847446795.png");
    }

    private void initView() {
        findViewById(R.id.btn_exit).setOnClickListener(this);
        findViewById(R.id.btn_clip).setOnClickListener(this);
    }

    private void initNotification() {
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(context, ScreenShotService.class);
        intent.putExtra("screen_shot", true);
        PendingIntent pendingIntent = PendingIntent.getService(context, 101,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.icon_share)
                .setContentTitle("截屏")
                .setContentText("点击截屏分享")
                .setContentIntent(pendingIntent)
                .build();
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }

    private void initServices() {
        startService(new Intent(context, ScreenShotService.class));
    }

    private void stopServices() {
        stopService(new Intent(context, ScreenShotService.class));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mNotificationManager.cancel(NOTIFICATION_ID);
        stopServices();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_exit:
                finish();
                break;
            case R.id.btn_clip:
                break;
        }
    }
}
